<?php

class admin_controller_system_menu_group extends admin_controller
{

	public function listing()
	{
		$model_menu_group = $this->get_admin_model();

		$template = $this->get_admin_template();
        $template->set_title('菜单分组管理');
		$template->set('groups', $model_menu_group->get_groups() );
		$template->display();
	}
	
	
    // 修改菜单组
    public function edit()
    {
        $id = get('id', 0, 'int');
        
        $menu_group = $this->get_admin_table('menu_group');
        if ($id != 0) $menu_group->load($id);
        
        $template = $this->get_admin_template();
        
        if ($id != 0)
            $template->set_title('修改菜单组');
        else
            $template->set_title('添加新菜单组');
        
        $template->set('menu_group', $menu_group);
        
        $return = get('return', null);
        if ($return === null) $return = base64_encode($_SERVER['HTTP_REFERER']);
        $template->set('return', $return);
        
        $template->display();
    }

    // 保存修改菜单组
    public function edit_save()
    {
        $id = post('id', 0, 'int');
        $return = post('return');

        $model = $this->get_admin_model();
        if ($model->edit(post()))
        {
            system_log( ($id == 0)?('添加菜单组: '.post('name')):('修改菜单组 '.post('name')));
            $this->redirect(base64_decode($return), $id == 0 ? '添加菜单组成功' : '修改菜单组成功');
        }
        else
            $this->redirect('./?action=system.menu_group.edit&id[]=' . $id . '&return=' . $return, $model->get_error(), 'error');
    }
	
}
?>